export const enum COUNTER_TYPE {
  "PLUS" = 'PLUS',
  "MINUS" = "MINUS",
  "DIV" = "DIV"
}

interface PlusAction {
  type: COUNTER_TYPE.PLUS
  payload: number
}

interface MinusAction {
  type: COUNTER_TYPE.MINUS
  payload: number
}

interface DivAction {
  type: COUNTER_TYPE.DIV
  payload: number
}

type CounterAction = PlusAction | MinusAction | DivAction

function CounterReducer(state: number, action: CounterAction) {
  switch (action.type) {
    case COUNTER_TYPE.PLUS:
      return (state + action.payload)
    case COUNTER_TYPE.MINUS:
      return (state - action.payload)
    case COUNTER_TYPE.DIV:
      return (state / action.payload)
    default:
      return state
  }
}

export default CounterReducer